package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsGoodsProductMapper;
import com.qf.pojo.DtsGoodsProduct;
import com.qf.service.DtsGoodsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Zwnan
 */
@Service
public class DtsGoodsProductServiceImpl implements DtsGoodsProductService {
    @Autowired
    private DtsGoodsProductMapper dtsGoodsProductMapper;

    @Override
    public Long selectCount() {
        return dtsGoodsProductMapper.selectCount(null);
    }

    @Override
    public List<DtsGoodsProduct> findByGoodId(Integer id) {
        QueryWrapper<DtsGoodsProduct> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("goods_id", id);
        queryWrapper.eq("deleted", false);
        return dtsGoodsProductMapper.selectList(queryWrapper);
    }

    @Override
    public void update(DtsGoodsProduct product) {
        dtsGoodsProductMapper.updateById(product);
    }

    @Override
    public void deleteByGid(Integer gid) {
        dtsGoodsProductMapper.updateByGid(gid);
    }

    @Override
    public void insertProducts(DtsGoodsProduct[] products) {
        for (DtsGoodsProduct product : products) {
            dtsGoodsProductMapper.insert(product);
        }
    }
}
